<html>
<head><meta charset="utf-8"><title>GlobalAlloc::realloc guarantees · t-libs/wg-allocators · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/index.html">t-libs/wg-allocators</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/GlobalAlloc.3A.3Arealloc.20guarantees.html">GlobalAlloc::realloc guarantees</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="228063007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/GlobalAlloc%3A%3Arealloc%20guarantees/near/228063007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vytautas Astrauskas [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/GlobalAlloc.3A.3Arealloc.20guarantees.html#228063007">(Feb 27 2021 at 14:58)</a>:</h4>
<p>(I have originally asked this in <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/GlobalAlloc.3A.3Arealloc.20guarantees">Unsafe Code Guidelines group</a>; Ralf suggested to try asking here.)</p>
<p>Hello, I have a question about the guarantees of  <a href="https://doc.rust-lang.org/alloc/alloc/trait.GlobalAlloc.html#method.realloc">GlobalAlloc::realloc</a>: what is guaranteed about the <strong>content</strong> of the memory block to which the pointer is returned if that pointer is not <code>null</code>?</p>
<p>I would assume that the returned memory block has the contents of the old block at its “front” because this is needed for the <code>Vec</code> to work. However, I do not see this explicitly written in the documentation. Did I miss something? Are there any reasons not to be explicit on to what extent the <code>realloc</code> preserves the memory content?</p>



<a name="228063805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/GlobalAlloc%3A%3Arealloc%20guarantees/near/228063805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/GlobalAlloc.3A.3Arealloc.20guarantees.html#228063805">(Feb 27 2021 at 15:12)</a>:</h4>
<p>That is the entire point of realloc - the documentation should just be tweaked to say that more explicitly.</p>



<a name="228159483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/GlobalAlloc%3A%3Arealloc%20guarantees/near/228159483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vytautas Astrauskas [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/GlobalAlloc.3A.3Arealloc.20guarantees.html#228159483">(Feb 28 2021 at 21:51)</a>:</h4>
<p>Here is my attempt to tweak the documentation: <a href="https://github.com/rust-lang/rust/pull/82628">https://github.com/rust-lang/rust/pull/82628</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>